<template>
  <div class="list">
    <div class="content-head" style="margin-bottom: 20px;">
      <div class="sort-keys">
        <a-input placeholder="输入关键字" style="width: 180px;margin-right:10px;" v-model="key" allowClear :size="size"
          @input="onSearch" />
        <a-button :size="size" type="primary" @click="refreshData" style="margin-right:10px;">刷新</a-button>
      </div>
      <div style="margin-top: 4px;" v-if="action_show">
        <a-button style="margin-left: 30px; float: right;" type="primary" @click="isExport2 = !isExport2">
          <span>实付查询</span>
        </a-button>
      </div>
    </div>
    <a-table class="table" :rowKey="row => row.uuid" :dataSource="list" :pagination="pagination" :size="size">
      <a-table-column title="群名称" width="40px">
        <template slot-scope="row">
          {{row.chat_name}}
        </template>
      </a-table-column>
      <a-table-column title="当前群人数" width="40px">
        <template slot-scope="row">
          <a href="javascript:;" @click="handleExternal(row.id)">{{row.user_total || 0}}</a>
        </template>
      </a-table-column>
      <a-table-column title="出入记录" width="80px">
        <template slot-scope="row">
          <a href="javascript:;" @click="handleGroupLog(row.id)">出入记录</a>
        </template>
      </a-table-column>
      <a-table-column title="今日抽/充实付总计" width="40px">
        <template slot-scope="row">
          {{row.order_sum_pay_money_price / 100 || 0}}
        </template>
      </a-table-column>
    </a-table>
    <ExportPopupQy @hide="isExport2=false" :isShow="isExport2"></ExportPopupQy>
    <a-modal title="群成员列表" style="top: 100px;" :visible="isExternal" width="1500px" @cancel="isExternal = false" :footer="null">
    <External v-if="isExternal" :group_id="group_id" @cancel="isExternal = false" @success="fetchData"></External>
    </a-modal>
    <a-modal title="群出入记录" style="top: 100px;" :visible="isGroupLog" width="1200px" @cancel="isGroupLog = false" :footer="null">
    <GroupLog v-if="isGroupLog" :group_id="group_id" @cancel="isGroupLog = false" @success="fetchData"></GroupLog>
    </a-modal>
  </div>
</template>
<script>
  import moment from 'moment'
  import ExportPopupQy from "./components/ExportPopupQy"
  import External from "./components/External.vue"
  import GroupLog from "./components/GroupLog.vue"

  const resourceType = 'qy-group'
  const resourceTypeText = '企业微信'

  export default {
    components: {
      ExportPopupQy,
      External,
      GroupLog
    },
    props: {
      selectMode: {
        type: Boolean
      },
      params: {
        type: Object
      },
      size: {
        type: String,
        default: 'default'
      }
    },
    data() {
      return {
        action_show : false,
        isExport2: false,
        isExternal: false,
        isGroupLog: false,
        group_id: 0,
        resourceTypeText,
        list: [],
        page: 1,
        per_page: 20,
        total: 0,
        key: '',
      }
    },
    watch: {
      params() {
        this.refreshData()
      },
    },
    computed: {
      pagination() {
        return {
          defaultPageSize: this.per_page,
          defaultCurrent: this.page,
          total: this.total,
          onChange: (e) => {
            this.page = e.current
            this.per_page = e.pageSize
            this.fetchData()
          }
        }
      }
    },
    filters: {},
    created() {
      this.action_show = this.$authCheck('UserQyGroup')
      this.fetchData()
    },
    methods: {
      handleExternal(group_id){
        this.isExternal = true;
        this.group_id = group_id;
      },
      handleGroupLog(group_id){
        this.isGroupLog = true;
        this.group_id = group_id;
      },
      refreshData() {
        this.page = 1
        this.key = ''
        this.fetchData()
      },
      onSearch(e) {
        this.fetchData()
        // clearTimeout(this.timeout)
        // this.timeout = setTimeout(() => {
        //   this.fetchData()
        // }, 300)
      },
      fetchData() {
        this.isEdit = false
        this.$http.get(`/${resourceType}`, {
          params: {
            ...this.params,
            page: this.page,
            per_page: this.per_page,
            key: this.key,
          }
        }).then(res => {
          this.list = res.data.list
          this.total = res.data.item_total
        }).finally(() => {
          this.loading = false
        })
      },
    }
  }
</script>
<style lang="scss" scoped>
  .content-head {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .table {
    .thumb {
      height: 60px;
      border-radius: 6px;
    }

    .content-image {
      height: 60px;
      width: 60px;
      margin-right: 10px;
      margin-bottom: 10px;
      object-fit: cover;
      border-radius: 10px;
      cursor: pointer;

      &:hover {
        opacity: 0.8;
      }
    }

    .user {
      display: flex;
      // flex-wrap: wrap;
      align-items: center;
      img {
        width: 26px;
        height: 26px;
        margin-right: 6px;
        border-radius: 50%;
        overflow: hidden;
      }
      .gender-man, .gender-woman {
        margin-left: 5px;
        font-size: 12px;
      }
      .gender-man {
        color: #409EFF;
      }
      .gender-woman {
        color: #F56C6C;
      }
    }
  }
</style>
